const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const cartNum=(name,index) =>{
  const app = getApp();
  const pages = getCurrentPages();
  if (name == 0) {
    app.globalData.carts[index].num++;
  } else {
    if (app.globalData.carts[index].num > 1) {
      app.globalData.carts[index].num--;
    } else {
      app.globalData.cartFlag.splice(index, 1);
      app.globalData.carts.splice(index, 1);
    }
  }
  pages[pages.length - 1].onShow();
  console.log(pages[pages.length - 1]);
  if(app.globalData.carts.length==0){
    pages[pages.length - 1].clearCart();
  }
}
module.exports = {
  formatTime: formatTime,
  cartNum: cartNum
}
